from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-20 14:02:18.919616
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 20, Aug, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1694
Nobs: 754.000 HQIC: -50.5088
Log likelihood: 9583.09 FPE: 9.37435e-23
AIC: -50.7215 Det(Omega_mle): 8.32613e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296405 0.055102 5.379 0.000
L1.Burgenland 0.107971 0.036614 2.949 0.003
L1.Kärnten -0.106924 0.019421 -5.506 0.000
L1.Niederösterreich 0.207945 0.076412 2.721 0.007
L1.Oberösterreich 0.107816 0.074343 1.450 0.147
L1.Salzburg 0.254617 0.039138 6.506 0.000
L1.Steiermark 0.037667 0.051042 0.738 0.461
L1.Tirol 0.108376 0.041347 2.621 0.009
L1.Vorarlberg -0.060143 0.035518 -1.693 0.090
L1.Wien 0.050973 0.066008 0.772 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063120 0.114816 0.550 0.582
L1.Burgenland -0.033455 0.076292 -0.439 0.661
L1.Kärnten 0.046959 0.040467 1.160 0.246
L1.Niederösterreich -0.175917 0.159219 -1.105 0.269
L1.Oberösterreich 0.400710 0.154908 2.587 0.010
L1.Salzburg 0.288695 0.081551 3.540 0.000
L1.Steiermark 0.106329 0.106356 1.000 0.317
L1.Tirol 0.314105 0.086155 3.646 0.000
L1.Vorarlberg 0.026357 0.074010 0.356 0.722
L1.Wien -0.029220 0.137540 -0.212 0.832
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189951 0.028326 6.706 0.000
L1.Burgenland 0.089867 0.018822 4.774 0.000
L1.Kärnten -0.008852 0.009984 -0.887 0.375
L1.Niederösterreich 0.260423 0.039281 6.630 0.000
L1.Oberösterreich 0.134827 0.038218 3.528 0.000
L1.Salzburg 0.045820 0.020120 2.277 0.023
L1.Steiermark 0.018348 0.026239 0.699 0.484
L1.Tirol 0.093761 0.021255 4.411 0.000
L1.Vorarlberg 0.058490 0.018259 3.203 0.001
L1.Wien 0.118536 0.033933 3.493 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107427 0.028825 3.727 0.000
L1.Burgenland 0.046323 0.019153 2.419 0.016
L1.Kärnten -0.014383 0.010159 -1.416 0.157
L1.Niederösterreich 0.192103 0.039972 4.806 0.000
L1.Oberösterreich 0.292712 0.038890 7.527 0.000
L1.Salzburg 0.111163 0.020474 5.430 0.000
L1.Steiermark 0.102502 0.026701 3.839 0.000
L1.Tirol 0.108898 0.021629 5.035 0.000
L1.Vorarlberg 0.069935 0.018580 3.764 0.000
L1.Wien -0.017457 0.034530 -0.506 0.613
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128352 0.052269 2.456 0.014
L1.Burgenland -0.050897 0.034732 -1.465 0.143
L1.Kärnten -0.040654 0.018422 -2.207 0.027
L1.Niederösterreich 0.171081 0.072484 2.360 0.018
L1.Oberösterreich 0.140474 0.070522 1.992 0.046
L1.Salzburg 0.288663 0.037126 7.775 0.000
L1.Steiermark 0.033762 0.048418 0.697 0.486
L1.Tirol 0.162444 0.039222 4.142 0.000
L1.Vorarlberg 0.100760 0.033693 2.991 0.003
L1.Wien 0.068086 0.062615 1.087 0.277
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056632 0.041704 1.358 0.174
L1.Burgenland 0.040302 0.027711 1.454 0.146
L1.Kärnten 0.050303 0.014699 3.422 0.001
L1.Niederösterreich 0.220871 0.057832 3.819 0.000
L1.Oberösterreich 0.286138 0.056267 5.085 0.000
L1.Salzburg 0.045136 0.029621 1.524 0.128
L1.Steiermark -0.001340 0.038631 -0.035 0.972
L1.Tirol 0.147328 0.031294 4.708 0.000
L1.Vorarlberg 0.072669 0.026882 2.703 0.007
L1.Wien 0.082784 0.049958 1.657 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177741 0.049817 3.568 0.000
L1.Burgenland -0.003812 0.033103 -0.115 0.908
L1.Kärnten -0.062097 0.017558 -3.537 0.000
L1.Niederösterreich -0.080528 0.069084 -1.166 0.244
L1.Oberösterreich 0.193582 0.067213 2.880 0.004
L1.Salzburg 0.057222 0.035384 1.617 0.106
L1.Steiermark 0.231786 0.046147 5.023 0.000
L1.Tirol 0.496137 0.037382 13.272 0.000
L1.Vorarlberg 0.047068 0.032112 1.466 0.143
L1.Wien -0.054798 0.059677 -0.918 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165533 0.057385 2.885 0.004
L1.Burgenland -0.010884 0.038131 -0.285 0.775
L1.Kärnten 0.067120 0.020226 3.319 0.001
L1.Niederösterreich 0.205905 0.079578 2.587 0.010
L1.Oberösterreich -0.068239 0.077424 -0.881 0.378
L1.Salzburg 0.210680 0.040759 5.169 0.000
L1.Steiermark 0.116626 0.053157 2.194 0.028
L1.Tirol 0.070981 0.043060 1.648 0.099
L1.Vorarlberg 0.121837 0.036990 3.294 0.001
L1.Wien 0.122104 0.068743 1.776 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360213 0.032970 10.925 0.000
L1.Burgenland 0.007316 0.021908 0.334 0.738
L1.Kärnten -0.023626 0.011621 -2.033 0.042
L1.Niederösterreich 0.214251 0.045721 4.686 0.000
L1.Oberösterreich 0.194369 0.044484 4.369 0.000
L1.Salzburg 0.044906 0.023418 1.918 0.055
L1.Steiermark -0.015504 0.030541 -0.508 0.612
L1.Tirol 0.105786 0.024740 4.276 0.000
L1.Vorarlberg 0.072899 0.021253 3.430 0.001
L1.Wien 0.041229 0.039496 1.044 0.297
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039988 0.144796 0.193203 0.154097 0.122761 0.108293 0.065238 0.220797
Kärnten 0.039988 1.000000 -0.005502 0.133215 0.039771 0.095412 0.431560 -0.053076 0.098609
Niederösterreich 0.144796 -0.005502 1.000000 0.337253 0.144577 0.297999 0.101517 0.181586 0.317553
Oberösterreich 0.193203 0.133215 0.337253 1.000000 0.227378 0.330669 0.173326 0.167025 0.263641
Salzburg 0.154097 0.039771 0.144577 0.227378 1.000000 0.145538 0.116963 0.145893 0.126069
Steiermark 0.122761 0.095412 0.297999 0.330669 0.145538 1.000000 0.149254 0.137106 0.076433
Tirol 0.108293 0.431560 0.101517 0.173326 0.116963 0.149254 1.000000 0.113524 0.146953
Vorarlberg 0.065238 -0.053076 0.181586 0.167025 0.145893 0.137106 0.113524 1.000000 0.003607
Wien 0.220797 0.098609 0.317553 0.263641 0.126069 0.076433 0.146953 0.003607 1.000000